//
//  MBDUploadGroupTitleCellModel.swift
//  MasterBoy
//
//  Created by kyson on 2024/9/5.
//

import Foundation
import YYText



class MBDUploadGroupTitleCellModel: MBDCommonCellModel {
    
    var titleLayout : YYTextLayout!
    var subtitleLayout : YYTextLayout!

    var titleModel : MBDGroupTitleModel! {
        didSet {
            
            let titleAttributeString = NSMutableAttributedString(string: self.titleModel.title ?? "")
            titleAttributeString.yy_font = UIFont.boldSystemFont(ofSize: 18)
            titleAttributeString.setDynamicTextColor()
            
            let titleContainer = YYTextContainer()
            let titleWidth = CGRectGetWidth(UIScreen.main.bounds) - 30
            titleContainer.size = CGSizeMake(titleWidth , CGFLOAT_MAX)
            titleContainer.maximumNumberOfRows = 1

            let titleLayout = YYTextLayout(container: titleContainer, text: titleAttributeString)

            self.titleLayout = titleLayout
            
            let subtitleAttributeString = NSMutableAttributedString(string: self.titleModel.subtitle ?? "")
            subtitleAttributeString.yy_font = UIFont.systemFont(ofSize: 12)
            subtitleAttributeString.yy_color = .red
            
            let subtitleContainer = YYTextContainer()
            let subtitleWidth = CGRectGetWidth(UIScreen.main.bounds) - 30
            subtitleContainer.size = CGSizeMake(subtitleWidth , CGFLOAT_MAX)
            subtitleContainer.maximumNumberOfRows = 1

            let subtitleLayout = YYTextLayout(container: subtitleContainer, text: subtitleAttributeString)

            self.subtitleLayout = subtitleLayout
        }
    }
    
    var tipsClickedBlock: ((String) -> ())?
    
    override func cellHeight() -> CGFloat {
        return 10 + titleLayout!.textBoundingSize.height + 10
    }
}
